// 
import 'package:flutter/material.dart';
import 'package:hktk_app/ienum/practice/ct_enum.dart';
import 'package:hktk_app/ienum/question/first_type_enum.dart';
import 'package:hktk_app/model/subject/rank_error_model.dart';
import 'package:hktk_app/util/font_util.dart';
import 'package:hktk_app/util/my_util.dart';

import 'package:hktk_app/util/view_util.dart';
import 'package:hktk_app/widget/question/stem_rich_text_widget.dart';

/// 内容显示组件
class SiftItemWidget extends StatelessWidget {
  /// 对应下标
  final int index;

  /// 对应数据
  final RankErrorModel rank;

  /// 人数
  final int count;

  /// 类型
  final CtEnum rType;

  const SiftItemWidget({
    super.key,
    required this.index,
    required this.rank,
    required this.count,
    required this.rType,
  });

  @override
  Widget build(BuildContext context) {
    debugPrint("siftItemWidget 组件 build 方法执行 ===> $index");
    debugPrint("");
    return GestureDetector(
      onTap: () {
        _onTapFunDj(context);
      },
      child: Container(
        padding: EdgeInsets.only(left: 20, right: 30),
        decoration: BoxDecoration(
          color: colorWhite1,
          borderRadius: BorderRadius.circular(10),
        ),
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            _sortItem(),
            hiSpace(width: 30),
            Expanded(
              child: Padding(
                padding: EdgeInsets.only(top: 30, bottom: 30),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    _stemItem(),
                    hiSpace(height: 15),
                    _tipsItem(),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  /// 序号标签显示
  _sortItem() {
    Color color1;
    Color color2;
    if (index == 1) {
      color1 = colorRed8;
      color2 = colorRed6;
    } else if (index == 2) {
      color1 = colorOrange5;
      color2 = colorOrange6;
    } else if (index == 3) {
      color1 = colorOrange3;
      color2 = colorYellow1;
    } else {
      color1 = colorGrey3;
      color2 = colorGrey5;
    }
    return ClipPath.shape(
      shape: BeveledRectangleBorder(
          borderRadius: BorderRadius.only(
            bottomLeft: Radius.circular(15),
            bottomRight: Radius.circular(15),
          )),
      child: Container(
        width: 30,
        height: 40,
        decoration: BoxDecoration(
          gradient: LinearGradient(
            colors: [color1, color2],
            begin: Alignment.topCenter,
            end: Alignment.bottomCenter,
          ),
        ),
        child: Center(
          child: Text(
            index.toString(),
            style: FontUtil.fontWhile1(20),
          ),
        ),
      ),
    );
  }

  /// 提示显示
  _tipsItem() {
    return Text(
      "$count 人做${rType == CtEnum.hotQue ? "过" : '错'}",
      style: FontUtil.fontGrey1(20),
    );
  }

  /// 内容显示
  _stemItem() {
    return StemRichTextWidget(
      text: MyUtil.getQuesStemStr(
        type: rank.type ?? FirstTypeEnum.singleChoice,
        stem: rank.stem,
      ),
      textStyle: TextStyle(fontSize: 20, fontWeight: FontWeight.w500),
    );
  }

  /// 点击方法
  void _onTapFunDj(BuildContext context) {
    Navigator.pushNamed(context, "/single-question",arguments: {
      "collectId": rank.collectId ?? "",
      "paperName": rank.collectName ?? "错题精选",
      "qId": rank.questionId!,
      "qType": rank.type ?? FirstTypeEnum.singleChoice,
      "rType": rank.collectType ?? rType,
    });
  }
}
